package com.xiaoma.myaudience.biz.task;

import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.json.JSONObject;

import android.content.Context;

import com.xiaoma.myaudience.biz.model.RankingListModel;
import com.xiaoma.myaudience.biz.util.Constant;
import com.xiaoma.myaudience.util.HttpUtils;
import com.xiaoma.myaudience.util.Logger;
import com.xiaoma.myaudience.util.model.ModelUtils;
import com.xiaoma.myaudience.util.task.BaseDataAsyncTask;

/**
 * 参加活动信息.
 * 
 */
public class RankingMoreTask extends BaseDataAsyncTask<Map<String, String>, Void, List<Map<String, Object>>>{
    private final static String TAG = "RankingMoreTask";
    
    public RankingMoreTask(Context context, int taskType, DataAsyncCallback callback) {
        super(context, taskType, callback);
    }

    
    @Override
    protected  List<Map<String, Object>> doInBackground(Map<String, String>... params) {  
    	String eventId = null;
    	String line = null;
		Map<String, String> cookie = null;
    	if (params != null) {
    		cookie = params[0];
		}
    	 List<Map<String, Object>> result = null;
        try {            
        	String cookiestr = Constant.LOGIN_COOKIE1+"="+cookie.get(Constant.LOGIN_COOKIE1)+";"+Constant.LOGIN_COOKIE2+"="+cookie.get(Constant.LOGIN_COOKIE2);
			Header[] headers = new BasicHeader[2];//("X-Online-Host",  format_CMWAP_ServerName(strPath));  
			headers[0]=new BasicHeader("Cookie", cookiestr);
			headers[1]=new BasicHeader("Accept-Language","zh-CN");
			eventId = cookie.get("url");
			line = cookie.get("line");
			String str = HttpUtils.getHttpStringResult(getHttpClient(), String.format(Constant.URL_RANK_MORE, eventId, line),
					null, headers, HttpUtils.GET, "GBK");
			
        	JSONObject jsonObject = new JSONObject(str);
        	if (jsonObject != null) {
    			Map<String, Object> objMap = ModelUtils.json2Map(jsonObject);
    			Map<String, Object> data = ModelUtils.getMapValue(objMap, RankingListModel.PARAM_DATA);
    			result = ModelUtils.getListMapValue(data, RankingListModel.PARAM_EVENTS);
			}
        } catch (Exception e) {
            Logger.e(TAG, "doInBackground error!!!", e);
        } finally {
            closeHttpClient();
        }
        
        return result;
    }
}
